﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace ConsoleWcfSerialization
{
	class Program
	{
		static void Main(string[] args)
		{
			XsdDataContractExporter xsdex = new XsdDataContractExporter();
			xsdex.Options = new ExportOptions() { };
			xsdex.Export(typeof(Employee));

			using (FileStream fs = new FileStream("c:\\Temp\\sample.xsd", FileMode.Create))
			{
				foreach (XmlSchema sch in xsdex.Schemas.Schemas())
					sch.Write(fs);
			}

			Employee emp = new Employee() { Data = "dfsfdsds dsfsdfs", Id = 123 };

			FileStream fs2 = new FileStream("c:\\temp\\empl.xml", FileMode.Create);
			DataContractSerializer dcs = new DataContractSerializer(typeof(Employee));
			dcs.WriteObject(fs2, emp);
			fs2.Close();
			fs2.Dispose();

			FileStream fs3 = new FileStream("c:\\temp\\empl2.xml", FileMode.Create);
			NetDataContractSerializer netdcs = new NetDataContractSerializer();
			netdcs.WriteObject(fs3, emp);
			fs3.Close();
			fs3.Dispose();

			Employee2 emp2 = new Employee2() { Data = "data emp2", Id = 111, Price = 12.34 };

			FileStream fs4 = new FileStream("c:\\temp\\empl3.xml", FileMode.Create);
			XmlSerializer xmlSer = new XmlSerializer(typeof(Employee2));
			netdcs.WriteObject(fs4, emp2);
			fs4.Close();
			fs4.Dispose();


			FileStream fs5 = new FileStream("c:\\temp\\json.xml", FileMode.Create);
			DataContractJsonSerializer jsonSer = new DataContractJsonSerializer(typeof(Employee));
			jsonSer.WriteObject(fs5, emp);
			fs5.Close();
			fs5.Dispose();

			

			Console.ReadLine();
		}
	}

	public class Employee2
	{
		public string Data
		{
			get;
			set;
		}

		public int Id
		{
			get;
			set;
		}

		public double Price
		{
			get;
			set;
		}
	}


	[DataContract]
	public class Employee
	{
		[DataMember]
		public string Data
		{
			get;
			set;
		}

		[DataMember]
		public int Id
		{
			get;
			set;
		}
	}
}
